package com.prs.crm.action.sys;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.person.PostSet;
import com.prs.crm.domain.sys.SysPostSet;
import com.prs.crm.service.person.PostSetService;
import com.prs.crm.service.sys.SysPostSetService;

public class SysPostSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private SysPostSet sysPostSet;
	private SysPostSetService sysPostSetService;
	private List<SysPostSet> postSet;
	public SysPostSet getSysPostSet() {
		return sysPostSet;
	}
	public void setSysPostSet(SysPostSet sysPostSet) {
		this.sysPostSet = sysPostSet;
	}

	private PaginationSupport pagination;
	private Integer[] ids;

	public SysPostSetService getSysPostSetService() {
		return sysPostSetService;
	}
	public void setSysPostSetService(SysPostSetService sysPostSetService) {
		this.sysPostSetService = sysPostSetService;
	}
	public List<SysPostSet> getPostSet() {
		return postSet;
	}
	public void setPostSet(List<SysPostSet> postSet) {
		this.postSet = postSet;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	
	@Action("listSysPostSet")
	public String listSysPostSet(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(SysPostSet.class);
		pagination =this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getSysPostSetService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editSysPostSet")
	public String editSysPostSet(){
		this.postSet=this.getSysPostSetService().getAllSysPostSet();
		return SUCCESS;
	}
//	@Action("editSysPostSets")
//	public String editSysPostSets(){
//		this.postSet=this.getSysPostSetService().getAllSysPostSet();
//		return SUCCESS;
//	}
	
	@Action(value="saveSysPostSet",results={
			@Result(name="success",type="redirect",location="listSysPostSet"),
			@Result(name="error",type="chain",location="editSysPostSet")
	})
	public String saveSysPostSet(){
		this.getSysPostSetService().save(sysPostSet);
		return SUCCESS;
	}
	
	@Action(value="removeSysPostSet",results={
			@Result(name="success",type="redirect",location="listSysPostSet"),
			@Result(name="error",type="chain",location="listSysPostSet")
	})
	public String removeSysPostSet(){
		if(ids==null){
			this.addActionError("请选中一行进行操作！");
			return ERROR;
		}
		this.getSysPostSetService().batchRemove(ids);
		return SUCCESS;
	}
}
